<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
        content="width=device-width, initial-scale=1.0,minimum-scale=1,maximum-scale=1,user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <!-- <link rel="stylesheet" type="text/css" href="css/index.css">
    <script type="text/javascript" src="js/index.js"></script>
    <style type="text/css"></style> -->
    <title>Document</title>
</head>

<body>
    <div class="">
    </div>

    <script>
        function getAJAX(url, success, error) {
            const xhr = new XMLHttpRequest()
            xhr.open('GET', url, true)
            xhr.send()
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        const data = xhr.responseText
                        success && success(data)
                    } else {
                        error && error(xhr.status)
                    }
                }
            }
        }

        function postAJAX(url, data, success, error) {
            const xhr = new XMLHttpRequest()
            xhr.open('POST', url, true)
            xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
            xhr.send(data)
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        const data = xhr.responseText
                        success && success(data)
                    } else {
                        error && error(xhr.status)
                    }
                }
            }
        }

        function getAJAXWithPromise(url) {
            const promise = new Promise((resolve, reject) => {
                const xhr = new XMLHttpRequest()
                xhr.open('GET', url, true)
                xhr.send()
                xhr.onreadystatechange = function () {
                    if (xhr.readyState === 4) {
                        if (xhr.status === 200) {
                            const data = xhr.responseText
                            resolve(data)
                        } else {
                            reject(xhr.status)
                        }
                    }
                }
            })
        }
    </script>
</body>

</html>